package com.taobaolite.user.store;

import com.taobaolite.item.Item;
import com.taobaolite.user.User;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "store")
public class Store {
    @Id
    private Long storeId;

    @OneToOne(cascade = CascadeType.REMOVE)
    @MapsId
    @JoinColumn(name = "storeId")
    private User user;

    private String name;
    private String description;

    @OneToMany(mappedBy ="store", cascade = CascadeType.ALL)
    @OnDelete(action = OnDeleteAction.CASCADE)
    private Set<Item> itemSet;

    public Store(User user, String name, String description, String logoPath) {
        this.user = user;
        this.name = name;
        this.description = description;
        this.logoPath = logoPath;
    }

    public Store() {}

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setLogoPath(String logoPath) {
        this.logoPath = logoPath;
    }

    public Long getStoreId() {
        return storeId;
    }

    public User getUser() {
        return user;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getLogoPath() {
        return logoPath;
    }

    public Set<Item> getItemSet() {
        return itemSet;
    }

    public void setItemSet(Set<Item> itemSet) {
        this.itemSet = itemSet;
    }

    private String logoPath;
}
